package com.employeemanage.controller;

import com.employeemanage.domain.bean.TblEmployee;
import com.employeemanage.domain.resp.PageResult;
import com.employeemanage.domain.resp.Result;
import com.employeemanage.domain.vo.EmployeeAddVo;
import com.employeemanage.domain.vo.EmployeeListVo;
import com.employeemanage.service.TblEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/employee-pet")
public class WebController {
    @Autowired
    private TblEmployeeService employeeService;

    //登录接口
    @PostMapping("/login")
    public Result login(@RequestBody TblEmployee account){
        TblEmployee result=null;
        result=employeeService.login(account);
        return Result.success(result);
    }

    //注册接口
    @PostMapping("/register")
    public Result<Map<String, Object>> addEmployee(@RequestBody EmployeeAddVo employeeAddVo) {

        try {
            Long employeeId = employeeService.addEmployee(employeeAddVo);
            Map<String, Object> data = new HashMap<>();
            data.put("id", employeeId);
            return Result.success(data);
        } catch (Exception e) {
            return Result.fail("新增员工失败：" + e.getMessage());
        }
    }

}
